package com.runvp.rest.biz;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.runvp.common.annotation.Log;
import com.runvp.common.enums.BusinessType;
import com.runvp.service.biz.domain.BizOrderItem;
import com.runvp.service.biz.service.IBizOrderItemService;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.page.TableDataInfo;

/**
 * 订单商品Controller
 * 
 * @author runvp
 * @date 2022-12-27
 */
@Controller
@RequestMapping("/biz/orderitem")
public class BizOrderItemController extends BaseController {
    private String prefix = "biz/orderitem";

    @Autowired
    private IBizOrderItemService bizOrderItemService;

    @RequiresPermissions("biz:orderitem:view")
    @GetMapping()
    public String orderitem(ModelMap mmap,String orderNo) {
        mmap.put("orderNo", orderNo);
        return prefix + "/orderitem";
    }

    /**
     * 查询订单商品列表
     */
    @RequiresPermissions("biz:orderitem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizOrderItem bizOrderItem) {
        startPage();
        List<BizOrderItem> list = bizOrderItemService.selectBizOrderItemList(bizOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @RequiresPermissions("biz:orderitem:export")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizOrderItem bizOrderItem) {
        List<BizOrderItem> list = bizOrderItemService.selectBizOrderItemList(bizOrderItem);
        ExcelUtil<BizOrderItem> util = new ExcelUtil<BizOrderItem>(BizOrderItem.class);
        return util.exportExcel(list, "订单商品数据");
    }

    /**
     * 新增订单商品
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存订单商品
     */
    @ParamValid
    @RequiresPermissions("biz:orderitem:add")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizOrderItem bizOrderItem) {
        return toAjax(bizOrderItemService.insertBizOrderItem(bizOrderItem));
    }

    /**
     * 修改订单商品
     */
    @RequiresPermissions("biz:orderitem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizOrderItem bizOrderItem = bizOrderItemService.selectBizOrderItemById(id);
        mmap.put("bizOrderItem", bizOrderItem);
        return prefix + "/edit";
    }
    /**
     * 订单商品详情
     */
    @RequiresPermissions("biz:orderitem:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizOrderItem bizOrderItem = bizOrderItemService.selectBizOrderItemById(id);
        mmap.put("bizOrderItem", bizOrderItem);
        return prefix + "/detail";
    }
    /**
     * 修改保存订单商品
     */
    @ParamValid
    @RequiresPermissions("biz:orderitem:edit")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizOrderItem bizOrderItem) {
        return toAjax(bizOrderItemService.updateBizOrderItem(bizOrderItem));
    }

    /**
     * 删除订单商品
     */
    @RequiresPermissions("biz:orderitem:remove")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizOrderItemService.deleteBizOrderItemByIds(ids));
    }
}
